package org.southyin.securitysamples.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.southyin.securitysamples.commons.CommonsResp;
import org.southyin.securitysamples.model.Article;
import org.southyin.securitysamples.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
@Api(tags = "ArticleController",description = "文章接口")
public class ArticleController {
    @Autowired
    ArticleService articleService;
    @ApiOperation(value = "查询文章接口",notes = "根据查询关键字分页查询文章信息")
    @GetMapping("/")
    public PageInfo listArticle(String keyWords,
                                long status,
                                @RequestParam(value = "pageNum",defaultValue = "1")
                                @ApiParam("页码") int pageNum,
                                @RequestParam(value = "pageSize",defaultValue = "10")
                                @ApiParam("每页记录个数") int pageSize) {
        return articleService.listArticle(keyWords,pageNum,pageSize,status);
    }

    @PostMapping("/")
    public CommonsResp insertArticle(@RequestBody Article article) {
        return articleService.insertArticle(article);
    }

    @PutMapping("/")
    public CommonsResp updateArticle(@RequestBody Article article) {
        return articleService.updateArticle(article);
    }

    @GetMapping("/getArticleById")
    public Article getArticleById(Long id) {
        return articleService.getArticleById(id);
    }

    @GetMapping("/getArticleDetailsById")
    public Article getArticleDetailsById(Long id,Integer status) {
        return articleService.getArticleDetailsById(id,status);
    }
}
